package com.bawei.day14_zuoye;

import android.Manifest;
import android.os.Build;
import android.os.Bundle;

import com.bawei.day14_zuoye.adapter.MyFragmentPagerAdapter;
import com.bawei.day14_zuoye.fragment.FiveFragment;
import com.bawei.day14_zuoye.fragment.FourFragment;
import com.bawei.day14_zuoye.fragment.OneFragment;
import com.bawei.day14_zuoye.fragment.ThreeFragment;
import com.bawei.day14_zuoye.fragment.TwoFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

public class MainActivity extends AppCompatActivity {

    private TabLayout tab;
    private ViewPager view_pager;
    private MyFragmentPagerAdapter myFragmentPagerAdapter;
    private List<Fragment> list;
    private List<String> title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
            requestPermissions(new String[]{
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE
            },101);
        }
        initView();

    }

    private void initView() {
        tab = (TabLayout) findViewById(R.id.tab);
        view_pager = (ViewPager) findViewById(R.id.view_pager);
        list = new ArrayList<>();
        title = new ArrayList<>();
        list.add(new OneFragment());
        list.add(new TwoFragment());
        list.add(new ThreeFragment());
        list.add(new FourFragment());
        list.add(new FiveFragment());
        title.add("111");
        title.add("111");
        title.add("111"); title.add("111");
        title.add("111");
        myFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(),list,title);
        view_pager.setAdapter(myFragmentPagerAdapter);
        tab.setupWithViewPager(view_pager);

    }
}
